<?php

class Adept_Renderer_Writer
{
    
    protected $response;
    
    public function __construct($response = null) 
    {
        $this->response = ($response === null) ? Adept_Context::getInstance()->getResponse() : $response;
    }    
    
    public function writeHtmlTag($name, $attributes = array(), $closed = false) 
    {
        
        if (!is_array($attributes)) {
            throw new Adept_Exception('$attributes value must be an array');
        }
        
        $this->write('<' . $name);
        foreach ($attributes as $key => $value) {
            if ($value !== null) {
                $this->write(' ' . $key . '="' . $value . '"');
            }
        }
        if ($closed) {
            $this->write(' /');
        }
        $this->write('>');
    }     
    
    public function write($string) 
    {
        $this->response->write($string);
    }    
    
}
